# str
website = 'http://www.python.org'
print(website[-3:])  # org

# 不能修改
# website[-3:] = 'com'  # TypeError: 'str' object does not support item assignment
#

# 格式化字符串 % 转换说明符
format = "Hello, %s. %s enough for ya?"
values = ('world', 'Hot')
print(format % values)  # Hello, world. Hot enough for ya?

# 格式化字符串 Template
from string import Template

tmpl = Template('Hello $who $what enough for?')
s = tmpl.substitute(who="wpp", what="coffee")
print(s)  # Hello wpp coffee enough for?

# 格式化字符串 format方法1 {}
s = "{} {} and {}".format("first", 'second', "third")
print(s)  # first second and third

# 格式化字符串 format方法2 {0} {1}
s = "{0}  {1} and {2}".format("first", 'second', "third")
print(s)  # first  second and third

s = "{2}-{2}  {1}_{1} and {0}+{0}".format("first", 'second', "third")
print(s)  # third-third  second_second and first+first

# 格式化字符串 format方法3 {name}
s = "name={name},and age={age}".format(name="wxx", age=29)
print(s)  # name=wxx,and age=29

from math import pi

s = "{name} is approximately {value:.2f}.".format(value=pi, name="π ")
print(s)  # π  is approximately 3.14.

# 格式化字符串 fString
s = f'pi={pi}'
print(s)  # pi=3.141592653589793

